//驼峰命名法 转为 带下划线命名
const formatName = (str) => {
    //studentNumber => student_number
    for (let i = 0; i < str.length; i++) {
        if (str[i] >= 'A' && str[i] <= 'Z') {
            str = str.slice(0, i) + '_' + str.slice(i);
            i++;
        }
    }
    return str;
}

//防抖函数
const debounce = (func, delay) => {
    let timer;
    return function() {
        const that = this;
        let args = arguments;
        clearTimeout(timer)
        timer = setTimeout(() => {
            func.call(that, args);
        }, delay);
    }
}

//把Object 转为 Array
const otoa = (obj) => {
    let newArr = [];
    for (const key in obj) {
        let o = {};
        o[key] = obj[key];
        newArr.push(o);
    }
    return newArr;
}


export default {
    formatName,
    debounce,
    otoa,
}